home *** CD-ROM | disk | FTP | other *** search
- /*
- search routine generated by gen.
- skip=no, match=fwd, shift=inc
- */
- /*
- * The authors of this software are Andrew Hume and Daniel Sunday.
- *
- * Copyright (c) 1991 by AT&T and Daniel Sunday.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose without fee is hereby granted, provided that this entire notice
- * is included in all copies of any software which is or includes a copy
- * or modification of this software and in all copies of the supporting
- * documentation for such software.
- *
- * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
- * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
- * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
- */
-
- #ifndef CHARTYPE
- #define CHARTYPE unsigned char
- #endif
- #define MAXPAT 256
-
- #include "stats.h"
-
- #ifndef TABTYPE
- #define TABTYPE long
- #endif
- typedef TABTYPE Tab;
-
- static struct
- {
- int patlen;
- CHARTYPE pat[MAXPAT];
- } pat;
-
- prep(base, m)
- CHARTYPE *base;
- register m;
- {
- CHARTYPE *skipc;
-
- pat.patlen = m;
- if(m > MAXPAT)
- abort();
- memcpy(pat.pat, base, m);
- skipc = 0;
- stats.len = m;
- }
-
- exec(base, n)
- CHARTYPE *base;
- {
- int nmatch = 0;
- register CHARTYPE *e, *s;
- register int s_offset;
- register CHARTYPE *p, *q;
- register CHARTYPE *ep;
-
- s = base+pat.patlen-1;
- e = base+n;
- s_offset = 1-pat.patlen;
- ep = pat.pat + pat.patlen;
- while(s < e){
- #ifdef STATS
- stats.slow++;
- #endif
- for(p = pat.pat, q = s+s_offset; p < ep; ){
- #ifdef STATS
- stats.cmp++;
- #endif
- if(*q++ != *p++)
- goto mismatch;
- }
- nmatch++;
- mismatch:
- s++;
- #ifdef STATS
- stats.step[1]++;
- #endif
- }
- return(nmatch);
- }
-